home *** CD-ROM | disk | FTP | other *** search
- ## -*-Tcl-*-
- # ###################################################################
- #
- # FILE: "temp.tcl"
- # created: 10/28/2000 {14:17:40 PM}
- # last update: 12/13/2000 {10:22:30 AM}
- # Author: Vince Darley
- #
- # Handling of temporary files in AlphaTcl. Used by ftpMenu, tex
- # mode. Goal is to provide utilities useful for extension authors,
- # and to allow a future version of AlphaTcl to provide only limited
- # access to the filesystem (and hence use a 'Safe Tcl' model of
- # extensions, so a malicious extension cannot be written).
- #
- # Code under development; the API may change.
- # ###################################################################
- ##
-
- namespace eval temp {}
-
- proc temp::path {pkg args} {
- global tcl_platform
- if {$tcl_platform(platform) == "macintosh"} {
- regsub -all "/" $args ":" args
- } else {
- regsub -all "~" $args "tilde" args
- }
- global PREFS
- set name [eval [list file join $PREFS $pkg] $args]
- file::ensureDirExists [file dirname $name]
- return $name
- }
-
- proc temp::isIn {pkg name} {
- global PREFS
- file::pathStartsWith $name [file join $PREFS $pkg]
- }
-
- proc temp::unique {pkg name} {
- global PREFS
- set count 1
- while {[file exists [set result [file join $PREFS $pkg $name$count]]]} {
- incr count
- }
- file::ensureDirExists [file dirname $result]
- return $result
- }
-
- proc temp::cleanup {pkg} {
- global PREFS
- if {[file exists [file join $PREFS $pkg]]} {
- catch {file delete -force [file join $PREFS $pkg]}
- }
- }
-
- proc temp::generate {pkg name code} {
- global PREFS
- set num 0
- for {set i [expr [string length $code] - 1]} {$i >= 0} {incr i -1} {
- scan [string index $code $i] "%c" char
- incr num $char
- }
- set name [file join $PREFS $pkg $name.$num]
- file::ensureDirExists [file dirname $name]
- return $name
- }
-